import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:taonile/config/config.dart';

import '../entity/apply_business_info_entity.dart';
import '../http/api.dart';
import '../routers/routers.dart';

///
/// 入驻审核状态页面
///
class MyStoreToJoinAudit extends StatefulWidget {
  const MyStoreToJoinAudit({Key? key}) : super(key: key);

  @override
  State<MyStoreToJoinAudit> createState() => _MyStoreToJoinAuditState();
}

class _MyStoreToJoinAuditState extends State<MyStoreToJoinAudit> {
  ApplyBusinessInfoEntity entity = ApplyBusinessInfoEntity();

  var statusStr = '';
  IconData statusIcon = Icons.timer_outlined;
  Color color = Config.colorText1;

  String logoStr = '店铺LOGO';
  String cateName = '经营类目';

  @override
  void initState() {
    super.initState();
    getdatas();
  }

  ////审核状态:waiting=等待审核,pass=通过,failed=未通过,not_applied=未申请
  getdatas() async {
    dynamic result = await Api.businessDetail();
    setState(() {
      entity = ApplyBusinessInfoEntity.fromJson(result);

      if (entity.code != 1) {
        return;
      }

      switch (entity.data.status) {
        case 'waiting':
          statusStr = '等待审核';
          statusIcon = Icons.timer_outlined;
          color = Config.colorText1;
          break;
        case 'pass':
          statusStr = '已通过';
          statusIcon = Icons.check_circle_outline;
          color = Config.colorMain;
          break;
        case 'failed':
          statusStr = '未通过';
          statusIcon = Icons.error_outline;
          color = Colors.red;
          break;
      }

      if (entity.data.type == 'online') {
        logoStr = '店铺LOGO';
        cateName = '经营类目';
      } else {
        logoStr = '门牌照片';
        cateName = '所属行业';
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      appBar: AppBar(
        title: const Text('店铺资质信息'),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              Container(
                //状态显示
                margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
                height: 100.w,
                padding: EdgeInsets.symmetric(horizontal: 25.w),
                decoration: BoxDecoration(
                  color: Config.colorWhite,
                  borderRadius: BorderRadius.circular(10.w),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Icon(
                          statusIcon,
                          size: 35.w,
                          color: color,
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 25.w),
                        ),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '审核状态：$statusStr',
                              style: TextStyle(fontSize: 26.sp, height: 1.2, color: color),
                            ),
                            Visibility(
                              visible: (entity.code == 1 && entity.data.status == 'failed')
                                  ? true
                                  : false,
                              child: Text(
                                '驳回原因：${entity.code == 1 ? entity.data.reason : ''}',
                                style: TextStyle(fontSize: 20.sp, height: 1.8, color: Colors.red),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                    Visibility(
                      visible: (entity.code == 1 && entity.data.status == 'failed') ? true : false,
                      child: Container(
                        width: 110.w,
                        height: 40.w,
                        margin: EdgeInsets.only(left: 170.w),
                        child: ElevatedButton(
                          clipBehavior: Clip.antiAlias,
                          onPressed: () {
                            if (entity.code == 1 && entity.data.type == 'online') {
                              Routes.navigateTo(context, Routes.myStoreToJoinMall,
                                  params: {'id': entity.data.id}).then((value) {
                                getdatas();
                              });
                            } else {
                              Routes.navigateTo(context, Routes.myStoreToJoinStore,
                                  params: {'id': entity.data.id}).then((value) {
                                getdatas();
                              });
                            }
                          },
                          style: ButtonStyle(
                            elevation: MaterialStateProperty.all(0),
                            backgroundColor: MaterialStateProperty.all(Config.colorMain),
                            shape: MaterialStateProperty.all(
                              RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(24.w),
                              ),
                            ),
                            side: MaterialStateProperty.all(
                              BorderSide(color: Config.colorMain, width: 2.w),
                            ),
                          ),
                          child: Text(
                            '修改',
                            style: TextStyle(fontSize: 18.sp, color: Config.colorWhite),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                margin: EdgeInsets.fromLTRB(20.w, 20.w, 20.w, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "店铺名称",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.name : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "注册地区",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1
                              ? '${entity.data.province}${entity.data.city}${entity.data.area}'
                              : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "详细地址",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.address : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          logoStr,
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        ClipRRect(
                          borderRadius: BorderRadius.circular(5.w),
                          child: CachedNetworkImage(
                            imageUrl: entity.code == 1 ? entity.data.logo : '',
                            fit: BoxFit.fill,
                            width: 60.w,
                            height: 60.w,
                            errorWidget: (context, url, error) {
                              return Image.asset(
                                'assets/images/icon_default_head.jpg',
                                width: 60.w,
                                height: 60.w,
                                fit: BoxFit.fill,
                              );
                            },
                          ),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          cateName,
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.categoryName : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                margin: EdgeInsets.fromLTRB(20.w, 20.w, 20.w, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "入驻人",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.occupantName : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "入驻人身份证",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.occupantId : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    // Divider(
                    //   color: Config.colorDivider,
                    //   height: 40.w,
                    //   thickness: 2.w,
                    // ),
                    // Row(
                    //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    //   crossAxisAlignment: CrossAxisAlignment.center,
                    //   children: [
                    //     Text(
                    //       "入驻人身份证有效期",
                    //       style: TextStyle(fontSize: 25.sp),
                    //     ),
                    //     Text(
                    //       "XXXXX",
                    //       style: TextStyle(fontSize: 25.sp),
                    //     ),
                    //   ],
                    // ),
                  ],
                ),
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                margin: EdgeInsets.fromLTRB(20.w, 20.w, 20.w, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "营业执照",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          (entity.code == 1 && entity.data.licensePhoto.isNotEmpty) ? '已上传' : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "是否三证合一",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          (entity.code == 1 && entity.data.isCertificates == '1') ? '是' : '否',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "统一社会信用代码",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.creditCode : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "营业执照有效期",
                          style: TextStyle(fontSize: 25.sp),
                        ),
                        Text(
                          entity.code == 1 ? entity.data.licenseTime : '',
                          style: TextStyle(fontSize: 25.sp),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.w),
                margin: EdgeInsets.fromLTRB(20.w, 20.w, 20.w, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Visibility(
                      visible: entity.code == 1 && entity.data.type == 'online',
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "产品出厂合格证",
                                style: TextStyle(fontSize: 25.sp),
                              ),
                              Text(
                                (entity.code == 1 && entity.data.factoryCertificate.isNotEmpty)
                                    ? '已上传'
                                    : '',
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ],
                          ),
                          Divider(
                            color: Config.colorDivider,
                            height: 40.w,
                            thickness: 2.w,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "检测报告",
                                style: TextStyle(fontSize: 25.sp),
                              ),
                              Text(
                                (entity.code == 1 && entity.data.inspectionReport.isNotEmpty)
                                    ? '已上传'
                                    : '',
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ],
                          ),
                          Divider(
                            color: Config.colorDivider,
                            height: 40.w,
                            thickness: 2.w,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "相关部门审批报告",
                                style: TextStyle(fontSize: 25.sp),
                              ),
                              Text(
                                (entity.code == 1 && entity.data.inspectionReport.isNotEmpty)
                                    ? '已上传'
                                    : '',
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ],
                          ),
                          Divider(
                            color: Config.colorDivider,
                            height: 40.w,
                            thickness: 2.w,
                          ),
                        ],
                      ),
                    ),
                    Visibility(
                      visible: entity.code == 1 && entity.data.type == 'offline',
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "卫生许可证",
                                style: TextStyle(fontSize: 25.sp),
                              ),
                              Text(
                                (entity.code == 1 && entity.data.sanitaryPermits.isNotEmpty)
                                    ? '已上传'
                                    : '',
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
